package org.boot.easyapi.permission.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.boot.easyapi.permission.entity.PermissionDO;
import org.boot.easyapi.permission.service.PermissionService;
import org.boot.easyapi.pojo.web.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

import static org.boot.easyapi.pojo.web.CommonResult.success;

@Tag(name = "EasyApi - 权限规则管理")
@RestController
@RequestMapping("/easyapi/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    @PostMapping("/insertDefPath")
    @Operation(summary = "插入默认放行路径规则")
    public CommonResult<Boolean> insertDefaultPathRule(@RequestBody PermissionDO permissionDO) {
        permissionService.insertDefaultPathRule(permissionDO);
        return success(true);
    }

    @PostMapping("/insertPath")
    @Operation(summary = "插入权限控制路径规则")
    public CommonResult<Boolean> insertPathRule(@RequestBody PermissionDO permissionDO) {
        permissionService.insertPathRule(permissionDO);
        return success(true);
    }

    @PostMapping("/insertIp")
    @Operation(summary = "插入IP白名单规则")
    public CommonResult<Boolean> insertIpRule(@RequestBody PermissionDO permissionDO) {
        permissionService.insertIpRule(permissionDO);
        return success(true);
    }

    @GetMapping("/list")
    @Operation(summary = "查询所有权限规则")
    public CommonResult<List<PermissionDO>> findList(PermissionDO permissionDO) {
        return success(permissionService.findList(permissionDO));
    }

    @GetMapping("/get")
    @Operation(summary = "查询指定权限规则")
    public CommonResult<PermissionDO> getById(@RequestParam("id") Long id) {
        return success(permissionService.findById(id));
    }




}
